Advertisement
eugene222

TPS Clock Window

Jul 11th, 2014
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.47 KB | None | 0 0
  1. #===============================================================================
  2. # ***TPS-Addon: TPS Clock***
  3. #
  4. # Author:     eugene222 (Evgenij)
  5. # Version:    1.3
  6. # Date:       01.09.2014
  7. # Requires:   Time and Period System V 1.2 by eugene222
  8. #===============================================================================
  9. # Changelog:
  10. #
  11. #   04.04.2014 - V. 1.0-alpha1  - script created
  12. #   05.04.2014 - V. 1.0         - fixed one bug, released the script
  13. #   09.04.2014 - V. 1.1     - made this compatible with Core 1.1
  14. #   21.05.2014 - V. 1.2         - added month, days and bg support
  15. #   01.09.2014 - V. 1.3     - custom position
  16. #
  17. #===============================================================================
  18. # Terms of Use:
  19. #   You can use this script for free and commercial projects as long as you give
  20. #   credits.
  21. #===============================================================================
  22. # Beschreibung:
  23. #
  24. #  Shows a simple hud, this hud is temporary, I will make something better when
  25. #  I have more time
  26. #
  27. #  If someone have ideas how I could design my HUD, pls send me a message.
  28. #
  29. # Scriptcalls:
  30. #  $game_time.show_clock    # show HUD
  31. #  $game_time.hide_clock    # hide HUD
  32. #
  33. #
  34. #===============================================================================
  35. module TPS_CLOCK
  36.   #-----------------------------------------------------------------------------
  37.   # :top_left, :top_right, :bottom_left, :bottom_right
  38.   # or you make and array like this: [x, y]  if you want to use custom coordinates
  39.   # eg. POS = [0, 120]
  40.   #-----------------------------------------------------------------------------
  41.   POS = :bottom_right
  42.  
  43.   #-----------------------------------------------------------------------------
  44.   # HUD VISIBLE AT NEW GAME ?
  45.   #-----------------------------------------------------------------------------
  46.   CLOCK_VISIBLE_AT_START = true
  47.  
  48.   #-----------------------------------------------------------------------------
  49.   # WINDOW OPACITY
  50.   #-----------------------------------------------------------------------------
  51.   WINDOW_OPACITY = 0
  52.  
  53.   #-----------------------------------------------------------------------------
  54.   # INPUT BUTTON TO SHOW THE HUD
  55.   #  - set to false if you dont want to use buttons to controll visibility.
  56.   #-----------------------------------------------------------------------------
  57.   CLOCK_BUTTON = :X
  58.  
  59.   #-----------------------------------------------------------------------------
  60.   # WHAT SHOULD HAPPEN WHEN YOU PRESS THE BUTTON?
  61.   #
  62.   #   :trigger :
  63.   #       -  SWITCH FROM CLOSED TO OPEN and OPEN TO CLOSED
  64.   #   :auto    :  
  65.   #       -  THE WINDOW IS VISIBLE FOR SOME TIME AND THEN CLOSES ITSELF
  66.   #-----------------------------------------------------------------------------
  67.   BUTTON_BEHAVIOUR = :trigger
  68.  
  69.   #-----------------------------------------------------------------------------
  70.   # IF BUTTON_BEHAVIOUR is :auto you can define the time (in frames) the window
  71.   # will be visible on button press.
  72.   #-----------------------------------------------------------------------------
  73.   OPEN_FRAMES = 180
  74.  
  75.   #-----------------------------------------------------------------------------
  76.   # USE AM PM?
  77.   #-----------------------------------------------------------------------------
  78.   AMPM = true
  79.   #-----------------------------------------------------------------------------
  80.   # TEXT BEHIND TIME (IF AMPM false)
  81.   #-----------------------------------------------------------------------------
  82.   CLOCK_VOCAB = "Uhr"
  83.  
  84.   #-----------------------------------------------------------------------------
  85.   # USE WEATHER ICON? WHICH DISPLAYS CURRENT WEATHER
  86.   #-----------------------------------------------------------------------------
  87.   USE_WEATHER_ICON = true
  88.  
  89.   #-----------------------------------------------------------------------------
  90.   # Icon Index for the weathers
  91.   #-----------------------------------------------------------------------------
  92.   WEATHER_ICONS = { :none => 110,:rain => 107, :storm => 109, :snow => 105}
  93.  
  94.   #-----------------------------------------------------------------------------
  95.   # USE A BACKGROUND PICTURE FOR THE HUD?
  96.   #-----------------------------------------------------------------------------
  97.   USE_BG_GRAPHIC = true
  98.  
  99.   #-----------------------------------------------------------------------------
  100.   # Name of the background picture, which need to be in Graphics/System
  101.   # muss.
  102.   #  - The size need to be 224x72
  103.   #-----------------------------------------------------------------------------
  104.   BG_GRAPHIC = "tps_gui1"
  105.  
  106.   #-----------------------------------------------------------------------------
  107. end
  108. #===============================================================================
  109. # END OF CONFIG
  110. #===============================================================================
  111. $imported ||= {}
  112. $imported[:e222_tps_clock] = 1.2
  113. unless $imported[:e222_tps_core]
  114.   msgbox("\"TBS-Addon: Clock\" requires the \"TBS-Core\" script.\n"+
  115.          "The \"TBS-Core\" script must be placed above the addon script.")
  116.   exit
  117. end
  118. #===============================================================================
  119. # Game_Time
  120. #   aliased methods: initialize, refresh_period
  121. #   new methods: show_clock, hide_clock, time_text, time_text_ampm
  122. #                ampm_hour, ampm_text
  123. #===============================================================================
  124. class Game_Time
  125.   #-----------------------------------------------------------------------------
  126.   attr_accessor   :clock_window_need_refresh
  127.   attr_reader     :clock_visible
  128.   #-----------------------------------------------------------------------------
  129.   alias :tps_clock_reinitialize           :reinitialize
  130.   #-----------------------------------------------------------------------------
  131.   # Initialize
  132.   #-----------------------------------------------------------------------------
  133.   def reinitialize
  134.     tps_clock_reinitialize
  135.     @clock_window_need_refresh = false if @clock_window_need_refresh.nil?
  136.     @clock_visible = TPS_CLOCK::CLOCK_VISIBLE_AT_START if @clock_visible.nil?
  137.   end
  138.   #-----------------------------------------------------------------------------
  139.   # Next Minute
  140.   #-----------------------------------------------------------------------------
  141.   alias :tps_clock_next_minute_e222     :next_minute
  142.   #-----------------------------------------------------------------------------
  143.   def next_minute
  144.     tps_clock_next_minute_e222  
  145.     @clock_window_need_refresh = true
  146.   end
  147.   #-----------------------------------------------------------------------------
  148.   # Next Day
  149.   #-----------------------------------------------------------------------------
  150.   alias :tps_clock_next_day_e222      :next_day
  151.   #-----------------------------------------------------------------------------
  152.   def next_day
  153.     tps_clock_next_day_e222
  154.     @clock_window_need_refresh = true    
  155.   end
  156.   #-----------------------------------------------------------------------------
  157.   # Next Month
  158.   #-----------------------------------------------------------------------------
  159.   alias :tps_clock_next_month_e222      :next_month
  160.   #-----------------------------------------------------------------------------
  161.   def next_month
  162.     tps_clock_next_month_e222
  163.     @clock_window_need_refresh = true
  164.   end
  165.   #-----------------------------------------------------------------------------
  166.   # Next Year
  167.   #-----------------------------------------------------------------------------
  168.   alias :tps_clock_next_year_e222     :next_year
  169.   #-----------------------------------------------------------------------------
  170.   def next_year
  171.     tps_clock_next_year_e222
  172.     @clock_window_need_refresh = true
  173.   end
  174.   #-----------------------------------------------------------------------------
  175.   # Time Text without AM/PM
  176.   #-----------------------------------------------------------------------------
  177.   def time_text
  178.     sprintf("%02d:%02d #{TPS_CLOCK::CLOCK_VOCAB}", hour, minute)
  179.   end
  180.   #-----------------------------------------------------------------------------
  181.   # Time Text with AM/PM
  182.   #-----------------------------------------------------------------------------
  183.   def time_text_ampm
  184.     sprintf("%02d:%02d %s", ampm_hour, minute, am_or_pm?)
  185.   end
  186.   #-----------------------------------------------------------------------------
  187.   # AM/PM Hour
  188.   #-----------------------------------------------------------------------------
  189.   def ampm_hour
  190.     h = hour % 12
  191.     h = 12 if h == 0
  192.     h
  193.   end
  194.   #-----------------------------------------------------------------------------
  195.   # AM or PM ?
  196.   #-----------------------------------------------------------------------------
  197.   def am_or_pm?
  198.     hour > 11 ? "PM" : "AM"
  199.   end
  200. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  201. # Script Call Overides:
  202. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  203.   #-----------------------------------------------------------------------------
  204.   # Resume Time
  205.   #-----------------------------------------------------------------------------
  206.   alias :tps_clock_resume_time_e222    :resume_time
  207.   def resume_time
  208.     tps_clock_resume_time_e222
  209.     @clock_window_need_refresh = true
  210.   end
  211.  
  212.   #-----------------------------------------------------------------------------
  213.   # Change Year
  214.   #-----------------------------------------------------------------------------
  215.   alias :tps_clock_change_year_e222    :change_year
  216.   def change_year(amount)
  217.     tps_clock_change_year_e222(amount)
  218.     @clock_window_need_refresh = true
  219.   end
  220.  
  221.   #-----------------------------------------------------------------------------
  222.   # Set Time
  223.   #-----------------------------------------------------------------------------
  224.   alias :tps_clock_set_time_e222    :set_time
  225.   def set_time(time)
  226.     tps_clock_set_time_e222(time)
  227.     @clock_window_need_refresh = true
  228.   end
  229.   #-----------------------------------------------------------------------------
  230.   # Set Day
  231.   #-----------------------------------------------------------------------------
  232.   alias :tps_clock_set_day_e222    :set_day
  233.   def set_day(day)
  234.     tps_clock_set_day_e222(day)
  235.     @clock_window_need_refresh = true
  236.   end
  237.   #-----------------------------------------------------------------------------
  238.   # Set Month
  239.   #-----------------------------------------------------------------------------
  240.   alias :tps_clock_set_month_e222    :set_month
  241.   def set_month(month)
  242.     tps_clock_set_month_e222(month)
  243.     @clock_window_need_refresh = true
  244.   end
  245.   #-----------------------------------------------------------------------------
  246.   # Set Year
  247.   #-----------------------------------------------------------------------------
  248.   alias :tps_clock_set_year_e222    :set_year
  249.   def set_year(year)
  250.     tps_clock_set_year_e222(year)
  251.     @clock_window_need_refresh = true
  252.   end
  253. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  254. # Clock Window Script Calls:
  255. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  256.   #-----------------------------------------------------------------------------
  257.   # Hide Clock
  258.   #-----------------------------------------------------------------------------
  259.   def hide_clock
  260.     @clock_visible = false
  261.   end
  262.   #-----------------------------------------------------------------------------
  263.   # Show Clock
  264.   #-----------------------------------------------------------------------------
  265.   def show_clock
  266.     @clock_visible = true
  267.     @clock_window_need_refresh = true
  268.   end
  269.   #-----------------------------------------------------------------------------
  270. end
  271. #===============================================================================
  272. # Window_TPSClock
  273. #   new class
  274. #===============================================================================
  275. class Window_TPSClock < Window_Base
  276.   #-----------------------------------------------------------------------------
  277.   include TPS_CLOCK
  278.   #-----------------------------------------------------------------------------
  279.   # Initialize
  280.   #-----------------------------------------------------------------------------
  281.   def initialize
  282.     super(*window_pos, window_width, window_height)
  283.     self.opacity = WINDOW_OPACITY
  284.     @open_counter = 0
  285.     self.visible = CLOCK_VISIBLE_AT_START
  286.     self.visible = false if CLOCK_BUTTON && BUTTON_BEHAVIOUR == :auto
  287.     create_bg if USE_BG_GRAPHIC
  288.     refresh
  289.   end
  290.   #-----------------------------------------------------------------------------
  291.   # Window Width
  292.   #-----------------------------------------------------------------------------
  293.   def window_width
  294.     return 224
  295.   end
  296.   #-----------------------------------------------------------------------------
  297.   # Half Contents Width
  298.   #-----------------------------------------------------------------------------
  299.   def hw_contents
  300.     contents.width / 2
  301.   end
  302.   #-----------------------------------------------------------------------------
  303.   # Create Background
  304.   #-----------------------------------------------------------------------------
  305.   def create_bg
  306.     @bg = Sprite.new
  307.     @bg.bitmap = Cache.system(BG_GRAPHIC)
  308.     @bg.visible = CLOCK_VISIBLE_AT_START
  309.     @bg.x = self.x
  310.     @bg.y = self.y
  311.     @bg.z = self.z - 1
  312.   end
  313.   #-----------------------------------------------------------------------------
  314.   # Window Height
  315.   #-----------------------------------------------------------------------------
  316.   def window_height
  317.     return fitting_height(2)
  318.   end
  319.   #-----------------------------------------------------------------------------
  320.   # Window Position
  321.   #-----------------------------------------------------------------------------
  322.   def window_pos
  323.     case POS
  324.     when :top_right
  325.       [Graphics.width - window_width, 0]
  326.     when :bottom_left
  327.       [0, Graphics.height - window_height]
  328.     when :bottom_right
  329.       [Graphics.width - window_width, Graphics.height - window_height]
  330.     when POS
  331.     else
  332.       POS.is_a?(Array) && POS.size == 2 ? POS : [0, 0]
  333.     end
  334.   end
  335.   #-----------------------------------------------------------------------------
  336.   # Time Text
  337.   #-----------------------------------------------------------------------------
  338.   def time_text
  339.     AMPM ? $game_time.time_text_ampm : $game_time.time_text
  340.   end
  341.   #-----------------------------------------------------------------------------
  342.   # Refresh
  343.   #-----------------------------------------------------------------------------
  344.   def refresh
  345.     return unless $game_time.clock_visible
  346.     contents.clear
  347.     draw_text(4, line_height, hw_contents - 28, line_height, dayandnumber_text)
  348.     draw_text(hw_contents - 28, line_height, hw_contents , line_height, time_text, 2)
  349.     draw_text(hw_contents , 0, hw_contents, line_height,current_month_vocab, month_alignment)
  350.     if USE_WEATHER_ICON
  351.       draw_icon(weather_icon, contents.width - 24, line_height) if weather_icon
  352.     end
  353.   end
  354.   #-----------------------------------------------------------------------------
  355.   # Day and Number Text
  356.   #-----------------------------------------------------------------------------
  357.   def dayandnumber_text
  358.     return "#{$game_time.current_day_vocab_short} #{current_day}"
  359.   end
  360.   #-----------------------------------------------------------------------------
  361.   # Current Day
  362.   #-----------------------------------------------------------------------------
  363.   def current_day
  364.     $game_time.current_day.to_s.rjust(2, '0')
  365.   end
  366.   #-----------------------------------------------------------------------------
  367.   # Current Month Text
  368.   #-----------------------------------------------------------------------------
  369.   def current_month_vocab
  370.      $game_time.current_month_vocab
  371.   end
  372.   #-----------------------------------------------------------------------------
  373.   # Current Day Text
  374.   #-----------------------------------------------------------------------------
  375.   def current_day_vocab
  376.     $game_time.current_day_vocab_short
  377.   end
  378.   #-----------------------------------------------------------------------------
  379.   # Weather Icon
  380.   #-----------------------------------------------------------------------------
  381.   def weather_icon
  382.     WEATHER_ICONS[$game_time.current_weather] rescue nil
  383.   end
  384.   def month_alignment
  385.     return (@bg ? 1 : 2)
  386.   end
  387.   #-----------------------------------------------------------------------------
  388.   # Update
  389.   #-----------------------------------------------------------------------------
  390.   def update
  391.     super
  392.     @bg.visible = self.visible unless @bg.nil?
  393.     return unless CLOCK_BUTTON
  394.     change_open if Input.trigger?(CLOCK_BUTTON)
  395.     @bg.visible = open? && self.visible unless @bg.nil?
  396.     @open_counter -= 1 if @open_counter > 0
  397.     close if @open_counter <= 0 && open? && BUTTON_BEHAVIOUR == :auto
  398.   end
  399.   #-----------------------------------------------------------------------------
  400.   # Change Open
  401.   #-----------------------------------------------------------------------------
  402.   def change_open
  403.     case BUTTON_BEHAVIOUR
  404.     when :trigger
  405.       if self.openness > 0
  406.         close
  407.       else
  408.         open
  409.         $game_time.show_clock
  410.       end
  411.     when :auto
  412.       @open_counter = OPEN_FRAMES
  413.       $game_time.show_clock
  414.       open
  415.     else
  416.       return
  417.     end
  418.   end
  419.   #-----------------------------------------------------------------------------
  420.   # Dispose
  421.   #-----------------------------------------------------------------------------
  422.   def dispose
  423.     @bg.bitmap.dispose
  424.     @bg.dispose
  425.     super
  426.   end
  427.   #-----------------------------------------------------------------------------
  428. end
  429. #===============================================================================
  430. # Scene_Map
  431. #   aliased methods: create_all_windows, update
  432. #   new methods: create_clock_window, refresh_tps_clock_window
  433. #===============================================================================
  434. class Scene_Map
  435.  
  436.   #-----------------------------------------------------------------------------
  437.   # * Create All Windows
  438.   #-----------------------------------------------------------------------------
  439.   alias :tps_clock_create_all_windows_e222  :create_all_windows
  440.   #-----------------------------------------------------------------------------
  441.   def create_all_windows
  442.     tps_clock_create_all_windows_e222
  443.     create_clock_window
  444.   end
  445.   #-----------------------------------------------------------------------------
  446.   # * Create Clock Window
  447.   #-----------------------------------------------------------------------------
  448.   def create_clock_window
  449.     @tps_clock_window = Window_TPSClock.new
  450.   end
  451.   #-----------------------------------------------------------------------------
  452.   # * Update
  453.   #-----------------------------------------------------------------------------
  454.   alias :tps_clock_update_e222              :update
  455.   def update
  456.     tps_clock_update_e222
  457.     refresh_tps_clock_window
  458.     @tps_clock_window.visible = $game_time.clock_visible
  459.   end
  460.   #-----------------------------------------------------------------------------
  461.   # Refresh Clock Window
  462.   #-----------------------------------------------------------------------------
  463.   def refresh_tps_clock_window
  464.     return unless $game_time.clock_window_need_refresh
  465.     @tps_clock_window.refresh
  466.     $game_time.clock_window_need_refresh = false
  467.   end
  468.   #-----------------------------------------------------------------------------
  469. end
  470. #===============================================================================
  471. # SCRIPT END
  472. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement