Advertisement
eugene222

TPS Period PopUp

Jul 11th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.07 KB | None | 0 0
  1. #===============================================================================
  2. # ***TPS-Addon: Period Pop-Up***
  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. #   03.04.2014 - V. 1.0-alpha1  - script created
  12. #   05.04.2014 - V. 1.0         - released script
  13. #   09.04.2014 - V. 1.1     - made this compatible with Core 1.1
  14. #   15.05.2014 - V. 1.2         - code optimized
  15. #   01.09.2014 - V. 1.3         - added 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. #  When a new period starts, there will be a popup similiar to the mapname which
  24. #  shows the new period.
  25. #
  26. # Scriptcalls:
  27. #  $game_time.enable_popup     # Enable Popup
  28. #  $game_time_disable_popup    # Disable Popup
  29. #
  30. #===============================================================================
  31. module TPS_POPUP_CONFIG
  32.   #-----------------------------------------------------------------------------
  33.   # PopUp show in <indoor> maps?
  34.   #-----------------------------------------------------------------------------
  35.   SHOW_INDOOR_POPUP = false
  36.  
  37.   #-----------------------------------------------------------------------------
  38.   # How long should the popup last? (In Frames)
  39.   #-----------------------------------------------------------------------------
  40.   ANIMATION_COUNT = 120
  41.  
  42.   #-----------------------------------------------------------------------------
  43.   # :left, :mid, :right
  44.   # or you can use an array like this: POSITION = [x, y] if you want custom position
  45.   #-----------------------------------------------------------------------------
  46.   POSITION = :right
  47.  
  48.   #-----------------------------------------------------------------------------
  49.   # The Graphic of the background need to be in the Graphics\System Folder
  50.   # The size should be 240px x 48px.
  51.   #-----------------------------------------------------------------------------
  52.   USE_CUSTOM_BACKGROUND = false
  53.  
  54.   CUSTOM_BACKGROUND = "popup_bg"
  55.  
  56.   #-----------------------------------------------------------------------------
  57.   # Disable PopUps for certain periods?
  58.   #-----------------------------------------------------------------------------
  59.   DISABLE_POPUP_FOR = [ # Diese Zeile nicht verändern!
  60.  
  61.     :noon,
  62.    
  63.   #-----------------------------------------------------------------------------
  64.   ] # Diese Zeile nicht verändern!
  65.   #-----------------------------------------------------------------------------
  66. end
  67. #===============================================================================
  68. # END OF CONFIG
  69. #===============================================================================
  70. $imported ||= {}
  71. $imported[:e222_tps_popup] = 1.2
  72. unless $imported[:e222_tps_core]
  73.   msgbox("\"TBS-Addon: Period Pop-Up\" requires the \"TBS-Core\" script.\n"+
  74.          "The \"TBS-Core\" script must be placed above the addon script.")
  75.   exit
  76. end
  77. #===============================================================================
  78. # Game_Time
  79. #   aliased methods: initialize, set_period
  80. #   new methods: enable_popup, disable_popup
  81. #===============================================================================
  82. class Game_Time
  83.   #-----------------------------------------------------------------------------
  84.   attr_accessor   :start_popup
  85.   #-----------------------------------------------------------------------------
  86.   # Initialize
  87.   #-----------------------------------------------------------------------------
  88.   alias :tps_pp_reinitialize_e222           :reinitialize
  89.   def reinitialize
  90.     tps_pp_reinitialize_e222
  91.     @start_popup    = false if @start_popup.nil?
  92.     @popup_enabled  = true  if @popup_enabled.nil?
  93.   end
  94.   #-----------------------------------------------------------------------------
  95.   # Refresh Period
  96.   #-----------------------------------------------------------------------------
  97.   alias :tps_pp_refresh_period_e222     :refresh_period
  98.   #-----------------------------------------------------------------------------
  99.   def refresh_period
  100.     tps_pp_refresh_period_e222
  101.     if popup_period? && @popup_enabled && show_indoor_popup?
  102.       @start_popup = true
  103.     end
  104.   end
  105. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  106. # Boolean Methods:
  107. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  108.  
  109.   #-----------------------------------------------------------------------------
  110.   # Show Indoor PopUp?
  111.   #-----------------------------------------------------------------------------
  112.   def show_indoor_popup?
  113.     $game_map.indoor? ? TPS_POPUP_CONFIG::SHOW_INDOOR_POPUP : true
  114.   end
  115.   #-----------------------------------------------------------------------------
  116.   # PopUp Period?
  117.   #-----------------------------------------------------------------------------
  118.   def popup_period?
  119.     !TPS_POPUP_CONFIG::DISABLE_POPUP_FOR.include?(@current_period)
  120.   end
  121. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  122. # PopUp Script Calls:
  123. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  124.   #-----------------------------------------------------------------------------
  125.   # Enable PopUp
  126.   #-----------------------------------------------------------------------------  
  127.   def enable_popup
  128.     @popup_enabled = true
  129.   end
  130.   #-----------------------------------------------------------------------------
  131.   # Disable PopUp
  132.   #-----------------------------------------------------------------------------
  133.   def disable_popup
  134.     @popup_enabled = false
  135.   end
  136.   #-----------------------------------------------------------------------------
  137. end # /Game_Time
  138. #===============================================================================
  139. # Window_TimePopUp
  140. #   new Class
  141. #===============================================================================
  142. class Window_TimePopUp < Window_Base
  143.   #-----------------------------------------------------------------------------
  144.   include TPS_POPUP_CONFIG
  145.   #-----------------------------------------------------------------------------
  146.   # Initialize
  147.   #-----------------------------------------------------------------------------
  148.   def initialize
  149.     super(window_x, window_y, window_width, window_height)
  150.     self.opacity = 0
  151.     self.contents_opacity = 0
  152.     @show_count = 0
  153.     refresh
  154.   end
  155.   #-----------------------------------------------------------------------------
  156.   # Window X
  157.   #-----------------------------------------------------------------------------
  158.   def window_x
  159.     case POSITION
  160.     when :mid
  161.       Graphics.width / 2 - window_width / 2
  162.     when :right
  163.       Graphics.width - window_width - window_y
  164.     else
  165.       POS.is_a?(Array) ? POS.first : window_y
  166.     end
  167.   end
  168.   #-----------------------------------------------------------------------------
  169.   # Window Y
  170.   #-----------------------------------------------------------------------------
  171.   def window_y
  172.     if POS.is_a?(Array)
  173.       POS.last
  174.     else
  175.       USE_CUSTOM_BACKGROUND ? -12 : 0
  176.     end
  177.   end
  178.   #-----------------------------------------------------------------------------
  179.   # Window Height
  180.   #-----------------------------------------------------------------------------
  181.   def window_height
  182.     USE_CUSTOM_BACKGROUND ? 72 : 48
  183.   end
  184.   #-----------------------------------------------------------------------------
  185.   # Window Width
  186.   #-----------------------------------------------------------------------------
  187.   def window_width
  188.     return 240
  189.   end
  190.   #-----------------------------------------------------------------------------
  191.   # Rect For Text
  192.   #-----------------------------------------------------------------------------
  193.   def rect_for_text
  194.     if USE_CUSTOM_BACKGROUND
  195.       temp_rect = contents.rect.clone
  196.       temp_rect.height = 24
  197.       temp_rect.y += 12
  198.       temp_rect
  199.     else
  200.       contents.rect
  201.     end
  202.   end
  203.   #-----------------------------------------------------------------------------
  204.   # Update
  205.   #-----------------------------------------------------------------------------
  206.   def update
  207.     super
  208.     if @show_count > 0
  209.       update_fadein
  210.       @show_count -= 1
  211.     else
  212.       update_fadeout
  213.     end
  214.   end
  215.   #-----------------------------------------------------------------------------
  216.   # * Update Fadein
  217.   #-----------------------------------------------------------------------------
  218.   def update_fadein
  219.     self.contents_opacity += 16
  220.   end
  221.   #-----------------------------------------------------------------------------
  222.   # * Update Fadeout
  223.   #-----------------------------------------------------------------------------
  224.   def update_fadeout
  225.     self.contents_opacity -= 16
  226.   end
  227.   #-----------------------------------------------------------------------------
  228.   # Open
  229.   #-----------------------------------------------------------------------------
  230.   def open
  231.     refresh
  232.     @show_count = ANIMATION_COUNT
  233.     self.contents_opacity = 0
  234.     self
  235.   end
  236.   #-----------------------------------------------------------------------------
  237.   # Refresh
  238.   #-----------------------------------------------------------------------------
  239.   def refresh
  240.     contents.clear
  241.     draw_background(contents.rect)
  242.     draw_text(rect_for_text, $game_time.period_text, 1)
  243.   end
  244.   #-----------------------------------------------------------------------------
  245.   # Draw Background
  246.   #-----------------------------------------------------------------------------
  247.   def draw_background(rect)
  248.     if USE_CUSTOM_BACKGROUND
  249.       create_custom_background(rect)
  250.     else
  251.       create_default_background(rect)
  252.     end
  253.   end
  254.   #-----------------------------------------------------------------------------
  255.   # Create Custom BG
  256.   #-----------------------------------------------------------------------------
  257.   def create_custom_background(rect)
  258.     bitmap = Cache.system(CUSTOM_BACKGROUND)
  259.     contents.blt(0,0, bitmap, bitmap.rect)
  260.   end
  261.   #-----------------------------------------------------------------------------
  262.   # Create Default BG
  263.   #-----------------------------------------------------------------------------
  264.   def create_default_background(rect)
  265.     temp_rect = rect.clone
  266.     temp_rect.width /= 2
  267.     contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
  268.     temp_rect.x = temp_rect.width
  269.     contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  270.   end
  271.   #-----------------------------------------------------------------------------
  272.   # * Back Color 1
  273.   #-----------------------------------------------------------------------------
  274.   def back_color1
  275.     Color.new(0, 0, 0, 192)
  276.   end
  277.   #-----------------------------------------------------------------------------
  278.   # * Back Color 2
  279.   #-----------------------------------------------------------------------------
  280.   def back_color2
  281.     Color.new(0, 0, 0, 0)
  282.   end
  283.   #-----------------------------------------------------------------------------
  284. end
  285. #===============================================================================
  286. # Scene_Map
  287. #   aliased methods: create_all_windows, update
  288. #   new methods:  create_time_popup_window, start_time_popup
  289. #===============================================================================
  290. class Scene_Map
  291.   #-----------------------------------------------------------------------------
  292.   # Create All Windows
  293.   #-----------------------------------------------------------------------------
  294.   alias :scene_map_create_all_windows_e222  :create_all_windows
  295.   #-----------------------------------------------------------------------------
  296.   def create_all_windows
  297.     scene_map_create_all_windows_e222
  298.     create_time_popup_window
  299.   end
  300.   #-----------------------------------------------------------------------------
  301.   # * Create Time PopUp Window
  302.   #-----------------------------------------------------------------------------
  303.   def create_time_popup_window
  304.     @time_popup_window = Window_TimePopUp.new
  305.   end
  306.   #-----------------------------------------------------------------------------
  307.   # * Update
  308.   #-----------------------------------------------------------------------------
  309.   alias :scene_map_update_e222              :update
  310.   def update
  311.     scene_map_update_e222
  312.     start_time_popup if $game_time.start_popup
  313.   end
  314.   #-----------------------------------------------------------------------------
  315.   # * Start Time PopUp
  316.   #-----------------------------------------------------------------------------
  317.   def start_time_popup
  318.     @time_popup_window.open
  319.     $game_time.start_popup = false
  320.   end
  321.   #-----------------------------------------------------------------------------
  322. end
  323. #===============================================================================
  324. # SCRIPT END
  325. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement